package com.bosssoft.springboot.demo4.job;

import com.bosssoft.springboot.demo4.service.EMailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @description 具体的schedule任务
 * @date 2020-6-10
 * @author ChenTong
 */
@Slf4j
@Component
public class EmailTask {
    @Autowired
    private EMailService eMailService;

    /**
     * @description 发送email 通过@schedule注解设置每三分钟方一次邮件
     * @return void 无返回值
     */
    @Scheduled(cron = "0 */3 * * * ? ") //每三分钟执行一次
    public void sendEmail() {
        //记录当前发送的时间
        Date date = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("现在的时间是{}",sf.format(date));
        log.info("开始发送邮件");
        //发送邮件
        eMailService.send("1329075259@qq.com","chen_tong_q@163.com","test","hello world");
    }
}
